-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor Entropy Calculations with Averaging Over Timesteps, Robust State Handling, and Enhanced Eigenvalue Filtering #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Replaced per-frame overwrite and post-loop sum/division with incremental running average updates, matching the approach used in `waterEntropy`. - Added `frame_counts` tracking to compute averages on the fly without storing all frame data. - Updated `build_covariance_matrices` and `update_force_torque_matrices` to initialize averages on first frame and update them in place each step. - Ensures final returned matrices are already averaged and representative of all processed timesteps.
- Removed division by `n_frames` in `entropy.py` to retain running averages - Replaced `+=` with `=` in `get_matrices` to avoid accumulation across frames - Simplified force and torque matrix updates in `levels.py` for consistency
…ues: - Added logging for complex and non-positive eigenvalues with index and value - Applied mask to filter out invalid values using np.isreal, np.isclose, and positivity check - Converted filtered values to pure real numbers using .real
- Replaced per-element logging with a single summary warning based on mask length - Improved performance and readability by avoiding redundant loops
…127-add-averaging-over-timesteps
- Replaced direct iteration over trajectory slices with `zip(index, frame)` - Ensures consistent indexing and avoids skipping final frame
… for `assign_conformation`: - Replaced direct iteration over trajectory slices with `zip(index, frame)` - Ensures consistent indexing and avoids skipping final frame
… dihedrals are present: - Added check to avoid calling `assign_conformation` if `get_dihedrals` returns an empty list - Prevented unnecessary allocation of empty `conformation` arrays - Ensured `states` are only generated when valid dihedrals exist - `conformational_entropy_calculation` is only called if the `state` is not empty
…127-add-averaging-over-timesteps
…afely: - Replaced ambiguous truth checks with type-safe logic for lists and NumPy arrays - Added guard against NoneType access for `states[group_id]` to prevent iteration errors
jimboid
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has had a lot of eyeballing from the whole team whilst it has been being developed. Test data suggests the code changes here are good. A very hard fought addition from the team here, well done all!
jkalayan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look great, looks like we have a working version of CodeEntropy :)
|
In entropy.py._process_conformational_entropy line 432 is: group_states = states[group_id] if group_id < len(states) else None I am not sure this is correct. In the grouping_molecules function (in group_molecules.py), the groups are dictionaries with the keys as the molecule number of the first molecule of that type. This means that the group_ids are all integers, but may not be consecutive. For grouping == "each" or most of our current examples it probably works, but if there are systems with multiples of molecules depending on how they are ordered in the topology weird things might happen if you try using the group_id as a counter rather than treating it as a label. |
…interpret -1 as the last frame
This was an issue relating the the |
Summary
This PR refactors and enhances the entropy computation to support averaging over timesteps, improve robustness against missing data, and streamline matrix operations. It also includes improvements to trajectory iteration, dihedral handling, and unit test coverage.
Changes
Implement Averaging Over Timesteps
build_covariance_matricesandupdate_force_torque_matricesto compute averages incrementally.Improve Robustness in Entropy and Dihedral Computation
Noneand empty states safely.Refactor Trajectory Iteration
zip(index, frame)for consistent indexing.Eigenvalue Filtering Enhancements
Unit Test Improvements
Default Grouping Configuration
eachtomoleculesfor more intuitive behavior.Impact